import useUserStore from '@/store/modules/user'

export default function useAuth() {

    function auth(value: string | string[]) {
        const userStore = useUserStore();
        let auth
        if (typeof value === 'string') {
            auth = value !== '' ? userStore.hasPermission(value) : true
        } else {
            auth = value.length > 0 ? value.some(item => userStore.hasPermission(item)) : true
        }
        return auth
    }

    function authAll(value: string[]) {
        const userStore = useUserStore();
        return value.length > 0 ? value.every(item => userStore.hasPermission(item)) : true
    }

    return {
        auth,
        authAll,
    }
}
